// miniprogram/pages/writePage/writePage.js
var _contentNavigationService = require("../../services/contentNavigationService.js");

var _moodStorage = require("../../services/MoodStorage.js");
var _timeStamp = require("../../services/timeStamp.js");

var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    moodList:{},
    message:"今天心情如何~",
    moodId:""
  },
  mood_bindtap: function(event){
    console.log(event);
    this.setData({
      message: "今天心情如何~"+this.data.moodList[event.target.id].name+"?",
      moodId:event.target.id
    });
    app.globalData.moodItem=app.globalData.moodList[this.data.moodId];

  },
  text_button_bindtap: function(event) {
    _contentNavigationService.navigateToAsync(
      _contentNavigationService.writeInPage,this.data.moodId
    )
  },

  result_button_bindtap: function (event) {
    var that=this;
    if(this.data.moodId!=""){
    _moodStorage.addMoodRecordAsync({
       TimeStamp:Date.parse(new Date()),//时间戳
       Weak:new Date().getDay(),
       month:_timeStamp.timeStampToDate(Date.parse(new Date()),'M'),
       Weather:app.globalData.todayWeather,
       Mood:this.data.moodId,
       MoodDegree:0,
    },function(){
      _contentNavigationService.navigateToAsync(
        _contentNavigationService.resultPage,that.data.moodId
      )
    },function(){
      wx.showToast({
        title: '记录失败',
        icon:'none',
        duration:1500,
      })
    }
    )
  }
  else{
    wx.showToast({
      title: '您还未选择心情哦',
      icon:'none',
      duration:1500,
    })
  }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      moodList: app.globalData.moodList
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})